package com.ruoyi.blog.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.blog.domain.BlogLeave;
import com.ruoyi.blog.service.IBlogLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 博客留言Controller
 * 
 * @author ruoyi
 * @date 2021-05-22
 */
@RestController
@RequestMapping("/blog/leave")
public class BlogLeaveController extends BaseController
{
    @Autowired
    private IBlogLeaveService blogLeaveService;

    /**
     * 查询博客留言列表
     */
    @PreAuthorize("@ss.hasPermi('blog:leave:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogLeave blogLeave)
    {
        startPage();
        List<BlogLeave> list = blogLeaveService.selectBlogLeaveList(blogLeave);
        return getDataTable(list);
    }

    /**
     * 导出博客留言列表
     */
    @PreAuthorize("@ss.hasPermi('blog:leave:export')")
    @Log(title = "博客留言", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BlogLeave blogLeave)
    {
        List<BlogLeave> list = blogLeaveService.selectBlogLeaveList(blogLeave);
        ExcelUtil<BlogLeave> util = new ExcelUtil<BlogLeave>(BlogLeave.class);
        return util.exportExcel(list, "博客留言数据");
    }

    /**
     * 获取博客留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('blog:leave:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(blogLeaveService.selectBlogLeaveById(id));
    }

    /**
     * 新增博客留言
     */
    @PreAuthorize("@ss.hasPermi('blog:leave:add')")
    @Log(title = "博客留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogLeave blogLeave)
    {
        return toAjax(blogLeaveService.insertBlogLeave(blogLeave));
    }

    /**
     * 修改博客留言
     */
    @PreAuthorize("@ss.hasPermi('blog:leave:edit')")
    @Log(title = "博客留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogLeave blogLeave)
    {
        return toAjax(blogLeaveService.updateBlogLeave(blogLeave));
    }

    /**
     * 删除博客留言
     */
    @PreAuthorize("@ss.hasPermi('blog:leave:remove')")
    @Log(title = "博客留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blogLeaveService.deleteBlogLeaveByIds(ids));
    }
}
